<?php

declare(strict_types=1);

namespace app\shop\controller\admin\goods;

use think\Request;
use sheep\controller\Backend;
use sheep\exception\SheepException;
use app\shop\model\goods\SkuPrice as SkuPriceModel;
use think\facade\Db;

class SkuPrice extends Backend
{
    public function initialize()
    {
        $this->model = new SkuPriceModel;
    }

    /**
     * skuPrices列表
     *
     * @return \think\Response
     */
    public function list($goods_id)
    {
        $skuPrices = SkuPriceModel::where('goods_id', $goods_id)->select();

        return success('获取成功', $skuPrices);
    }



    /**
     * skuPrices编辑
     *
     * @param  $id
     * @return \think\Response
     */
    public function edit(Request $request, $id)
    {
        $params = $this->request->only([
            'status',
        ]);

        $id = explode(',', $id);
        Db::transaction(function () use ($id, $params) {
            foreach ($this->model->whereIn('id', $id)->cursor() as $skuPrice) {
                $skuPrice->save($params);
            }
        });

        return success('更新成功');
    }
}
